@echo off
setlocal enabledelayedexpansion

echo Building JSZ Language Support extension...

where node >nul 2>&1
if errorlevel 1 (
    echo Error: Node.js not found, please install Node.js first
    pause
    exit /b 1
)

where npm >nul 2>&1
if errorlevel 1 (
    echo Error: npm not found, please ensure Node.js is properly installed
    pause
    exit /b 1
)

echo Installing dependencies...
call npm install
if errorlevel 1 (
    echo Error: Failed to install dependencies
    pause
    exit /b 1
)

echo Installing vsce...
call npm install -g @vscode/vsce
if errorlevel 1 (
    echo Error: Failed to install vsce
    pause
    exit /b 1
)

echo Packaging extension...
call npx vsce package
if errorlevel 1 (
    echo Error: Failed to package extension
    pause
    exit /b 1
)

echo.
echo JSZ Language Support extension built successfully!
echo.
echo The generated .vsix file can be installed in VS Code:
echo 1. Open VS Code
echo 2. Press Ctrl+Shift+P to open command palette
echo 3. Type "Extensions: Install from VSIX..."
echo 4. Select the generated .vsix file
echo.
pause